from image_utils import logging # 从image_utils.py中导入logging对象


def crop_image(image, crop_region):
    """
    裁剪图像
    :param image: 输入图像，numpy.ndarray 对象
    :param crop_region: 裁剪区域,格式为(上,下,左,右)
    :return: 裁剪后的图像
    """
    try:
        logging.info(f"开始裁剪图像，裁剪区域,{crop_region}")

        # 从 crop_region 中提取上、下、左、右的坐标
        top, bottom, left, right = crop_region

        # 使用 numpy 的切片操作裁剪图像
        cropped_image = image[top:bottom, left:right]

        return cropped_image
    except Exception as e:
        raise ValueError(f"Error occurred while cropping image: {e}")

